import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout 项目骨架 */
import Layout from '@/layout'

//常量路由（不管什么角色都可以看到的路由）
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '*',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard', //重定向到二级路由dashboard
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '首页', icon: 'dashboard' }
      },
    ]
  },
  // {
  //   path: '/workspace',
  //   component: Layout,
  //   redirect: '/dashboard', //重定向到二级路由dashboard
  //   children: [
  //     {
  //       path: 'workspace',
  //       name: 'WorkSpace',
  //       component: () => import('@/views/workspace/index'),
  //       meta: { title: '工作台', icon: 'el-icon-sunny' }
  //     },
  //   ]
  // },

  {
    path: '/demonstration',
    component: Layout,
    name: 'demonstration',
    meta: { title: '演示', icon: 'el-icon-s-claim' },
    children: [
      {
        path: 'map',
        name: 'Map',
        component: () => import('@/views/demonstration/map'),
        meta: { title: '地图', icon: 'el-icon-location' }
      },
      {
        path: 'shortvideo',
        name: 'ShortVideo',
        component: () => import('@/views/demonstration/shortvideo'),
        meta: { title: '短视频', icon: 'el-icon-medal-1' }
      },
    ]
  },

  {
    path: '/system',
    component: Layout,
    name: 'system',
    meta: { title: '系统管理', icon: 'el-icon-lock' },
    children: [
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/system/user'),
        meta: { title: '用户管理', icon: 'el-icon-s-custom' }
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('@/views/system/role'),
        meta: { title: '角色管理', icon: 'el-icon-goods' }
      },
      {
        path: 'menu',
        name: 'menu',
        component: () => import('@/views/system/menu'),
        meta: { title: '菜单管理', icon: 'el-icon-menu' }
      },
    ]
  },
  {
    path: '/content',
    component: Layout,
    name: 'content',
    meta: { title: '内容管理', icon: 'el-icon-platform-eleme' },
    children: [
      {
        path: 'write',
        name: 'write',
        component: () => import('@/views/content/article/write'),
        meta: { title: '写文章', icon: 'el-icon-edit' }
      },
      {
        path: 'article',
        name: 'article',
        component: () => import('@/views/content/article'),
        meta: { title: '文章管理', icon: 'el-icon-document' }
      },
      {
        path: 'category',
        name: 'category',
        component: () => import('@/views/content/category'),
        meta: { title: '分类管理', icon: 'el-icon-s-management' }
      },
      {
        path: 'tag',
        name: 'tag',
        component: () => import('@/views/content/tag'),
        meta: { title: '标签管理', icon: 'el-icon-s-promotion' }
      },
    ]
  },

]

//异步理由:不同的用户（角色），需要过滤筛选出的路由，称之为异步路由
//有的用户可以看见测试管理、有的看不见
export const asyncRoutes = [
  // {
  //   path: '/test',
  //   component: Layout,
  //   name: 'test',
  //   meta: { title: '测试管理', icon: 'el-icon-goods' },
  //   children: [
  //     {
  //       path: 'test1',
  //       name: 'test1', 
  //       component: () => import('@/views/test/test1'),
  //       meta: { title: '测试管理1' }
  //     },
  //     {
  //       path: 'test2',
  //       name: 'test2',
  //       component: () => import('@/views/test/test2'),
  //       meta: { title: '测试管理2' }
  //     },
  //   ]
  // },
];

//任意路由：当路径出现错误的时候重定向404
// 404 page must be placed at the end !!!
// export const anyRoutes ={ path: '*', redirect: '/404', hidden: true };

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
